package ControlLayer;
import ModelLayer.*;
import DBLayer.*;

import java.util.*;

public class CtrEquipment {
	public ArrayList<Supplier> findAllSupplier()
    {
      IFDBSupplier dbEmp = new DBSupplier();
      ArrayList<Supplier> allEmp = new ArrayList<Supplier>();
      allEmp = dbEmp.getAllSuppliers(false);
      return allEmp;
    }
    public Supplier findByName(String fname)
    {
        IFDBSupplier dbEmp = new DBSupplier();
        return dbEmp.searchSupplierName(fname, true);
    }
      public Supplier findBySsn(int suID)
    {
        IFDBSupplier dbSup = new DBSupplier();
        return dbSup.searchSupplierID(suID, true);
    }
      public int updateSup(int suID, String name, String address, String salary, String country,int phone)
      {
          IFDBSupplier dbSup = new DBSupplier();
          Supplier su = new Supplier();
          su.setSuID(suID);
          su.setName(name);
          su.setAddress(address);
          su.setCountry(country);
          su.setE_mail(salary);
          su.setPhone(phone);
          return  dbSup.updateSupplier(su);
          
          
      }
      //find the projects the Supplier is working on
     
      public void insertNew(String fname)
      {    
           Supplier suObj = new Supplier();
           suObj.setName(fname);
                
           try{
            DbConnection.startTransaction();
            DBSupplier dbSu = new DBSupplier();
            dbSu.insertSupplier(suObj);
            DbConnection.commitTransaction();
           }
           catch(Exception e)
           {
               DbConnection.rollbackTransaction();
           }
      }
    
    
}

